import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '@/views/Login';
import Home from '@/views/Home';

import SellerList from '@/views/cv/SellerList';
import BrandList from '@/views/cv/BrandList';
import AdminList from '@/views/cv/xhp/AdminList';
import AddAdmin from '@/views/cv/xhp/AddAdmin';
import UpdateAdmin from '@/views/cv/xhp/UpdateAdmin';
import SpecificationList from '@/views/cv/lgs/SpecificationList';
Vue.use(VueRouter)

import axios from 'axios';

Vue.prototype.axios=axios;
const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children:[
      {
        path: '/sellerList',
        name: 'SellerList',
        component: SellerList
      },
      {
        path: '/brandList',
        name: 'BrandList',
        component: BrandList
      },
      {
        path: '/brandList/:id',
        name: 'BrandList',
        component: BrandList
      },
      {
        path: '/adminList/:id',
        name: 'AdminList',
        component: AdminList
      },
      {
        path: '/addAdmin/:id',
        name: 'AddAdmin',
        component: AddAdmin
      },
      {
        path: '/updateAdmin/:id',
        name: 'UpdateAdmin',
        component: UpdateAdmin
      },
      {
        path: '/specificationList',
        name: 'SpecificationList',
        component: SpecificationList
      },

    ]
  }


]

const router = new VueRouter({
  routes
})


//路由拦截
router.beforeEach( function (to, from, next) {
// debugger
  if (to.path == '/login'){
    return next();
  }

  //使用 sessionStorage 获取浏览器中有没有数据
  var user = sessionStorage.getItem("user1");
  if(user!=null&&""!=user){
    return next();
  }

  return next('/login');

});


export default router
